<?php
class UsersController extends AppController 
{
	var $name = 'Users';
	
	function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow(array('*'));
	}
	
	function login() {
		if ($this->Session->read('Auth.User')) {
			$this->Session->setFlash('Je bent ingelogged');
			$this->redirect('/contents', null, true);
		}
	}
	function logout()
	{
		$this->Session->setFlash('uitgelogged');
		$this->redirect($this->Auth->logout());
	}
	
	function add() {
        if (!empty($this->data)) {
            $this->User->create();
            if ($this->User->save($this->data)) {
                $this->Session->setFlash(__('The User has been saved', true));
                //$this->redirect(array($this->referer()));
            } else {
                $this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
            }
        }
        $groups = $this->User->Group->find('list');
        $this->set(compact('groups'));
    }
	
	function initDB() 
	{
		$group =& $this->User->Group;
		//Allow admins to everything
		$group->id = 1;     
		$this->Acl->allow($group, 'controllers');
		
		//we add an exit to avoid an ugly "missing views" error message
		echo "all done";
		exit;
	}

}
?>